package yun2.shuxue;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 非十进制 转 十进制
 * 按权展开:各位的单位数值代表的大小-权值
 *  123D = 1*100 + 2*10 + 3*1 = 1*10^2 + 2*10^1 + 3*10^0
 *  1011B = 1*2^3 + 0*2^2 + 1*2^1 + 1*2^0  
 *  
 *  1011B 123O a1B2H
 *  
 *  二进制中的十：01 +1 = 10
 *  八进制中的十：07 +1 = 10
 */

public class JinZhiZhuanHuan {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = br.readLine();
		String[] arr = line.split(" ");
		
		for(int i=0;i<arr.length;i++){
			String str = arr[i];
			String front = arr[i].substring(0, str.length()-1);//求字串，区间前闭后开[)
			char last = str.charAt(str.length()-1);
			if(last == 'B') {
				System.out.print(Integer.parseInt(front, 2));
			}
			if(last == 'O') {
				System.out.print(Integer.parseInt(front, 8));
			}
			if(last == 'H') {
				System.out.print(Integer.parseInt(front, 16));
			}		
			if(i<arr.length - 1) {
				System.out.print(" ");
			}
		}			
	}
}
